# 基于langchain 的 agent
from langchain.agents import initialize_agent
from patagent.llm import PatsnapLLM
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from patagent.tools import multiply


llm = PatsnapLLM()

# initialize conversational memory
conversational_memory = ConversationBufferWindowMemory(
        memory_key='chat_history',
        k=5,
        return_messages=True
)

tools = [multiply()]

# initialize agent with tools
agent = initialize_agent(
    agent='chat-conversational-react-description',
    tools=tools,
    llm=llm,
    verbose=True,
    max_iterations=3,
    early_stopping_method='generate',
    memory=conversational_memory
)

agent("What is 3 * 12?")